﻿use SSODemo;

--region Drop Existing Procedures

IF OBJECT_ID(N'[usp_InsertRole]') IS NOT NULL
	DROP PROCEDURE [usp_InsertRole]

IF OBJECT_ID(N'[usp_UpdateRole]') IS NOT NULL
	DROP PROCEDURE [usp_UpdateRole]

IF OBJECT_ID(N'[usp_DeleteRole]') IS NOT NULL
	DROP PROCEDURE [usp_DeleteRole]

IF OBJECT_ID(N'[usp_SelectRole]') IS NOT NULL
	DROP PROCEDURE [usp_SelectRole]

IF OBJECT_ID(N'[usp_SelectRolesAll]') IS NOT NULL
	DROP PROCEDURE [usp_SelectRolesAll]

IF OBJECT_ID(N'[usp_InsertRolePermission]') IS NOT NULL
	DROP PROCEDURE [usp_InsertRolePermission]
--endregion

GO

--region [usp_InsertRole]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_InsertRole]
-- Date Generated: 2009-04-27
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [usp_InsertRole]
	@Name varchar(255),
	@DateCreated datetime,
	@Remark varchar(255),
	@ID uniqueidentifier
AS

SET NOCOUNT ON

INSERT INTO [Role] (
	[ID],
	[Name],
	[DateCreated],
	[Remark]
) VALUES (
	@ID,
	@Name,
	@DateCreated,
	@Remark
)

--endregion

GO

--region [usp_UpdateRole]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_UpdateRole]
-- Date Generated: 2009-04-27
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [usp_UpdateRole]
	@ID uniqueidentifier,
	@Name varchar(255),
	@DateCreated datetime,
	@Remark varchar(255)
AS

SET NOCOUNT ON

UPDATE [Role] SET
	[Name] = @Name,
	[DateCreated] = @DateCreated,
	[Remark] = @Remark
WHERE
	[ID] = @ID

--endregion

GO

--region [usp_DeleteRole]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_DeleteRole]
-- Date Generated: 2009-04-27
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [usp_DeleteRole]
	@ID uniqueidentifier
AS

SET NOCOUNT ON

DELETE FROM [Role]
WHERE
	[ID] = @ID

--endregion

GO

--region [usp_SelectRole]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_SelectRole]
-- Date Generated: 2009-04-27
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [usp_SelectRole]
	@ID uniqueidentifier
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[ID],
	[Name],
	[DateCreated],
	[Remark]
FROM
	[Role]
WHERE
	[ID] = @ID

--endregion

GO

--region [usp_SelectRolesAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_SelectRolesAll]
-- Date Generated: 2009-04-27
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [usp_SelectRolesAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[ID],
	[Name],
	[DateCreated],
	[Remark]
FROM
	[Role]

--endregion

GO

--region [usp_InsertRolePermission]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_InsertRolePermission]
-- Date Generated: 2009-04-27
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertRolePermission]
	@RoleID uniqueidentifier,
	@PermissionID uniqueidentifier
AS

SET NOCOUNT ON

INSERT INTO [RolePermission] (
	[RoleID],
	[PermissionID]
) VALUES (
	@RoleID,
	@PermissionID
)

--endregion

GO

